<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="/favicon.ico">
<title>System</title>
<link type="text/css" href="/Public/jcms/css/layout.css" rel="stylesheet" />	
<script type="text/javascript" src="/Public/jcms/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/Public/jcms/js/easyTooltip.js"></script>
<script type="text/javascript" src="/Public/jcms/js/jquery-ui-1.7.2.custom.min.js"></script>
<script type="text/javascript" src="/Public/jcms/js/jquery.wysiwyg.js"></script>
<script type="text/javascript" src="/Public/jcms/js/hoverIntent.js"></script>
<script type="text/javascript" src="/Public/jcms/js/superfish.js"></script>
<script type="text/javascript" src="/Public/jcms/js/custom.js"></script>
<script type="text/javascript" src="/Public/jcms/js/jquery.validate.js"></script>
<script type="text/javascript" src="/Public/jcms/js/common.js"></script>
<script type="text/javascript">
var APP = "/index.php?s=";
</script>
<style>
body{font-size:12px;}
body a{outline:none;blr:expression(this.onFocus=this.blur());}
*body{font:"Courier New", Courier, monospace;}
html{overflow-x: hidden; overflow-y: auto;}
.red{color:#F00;}
input.error{background:none;border:red 1px dotted;}
label.error{background:none;color:#F00;border:none;}
select.error{background:none;border:red 1px dotted;}
input, textarea, select{border:1px solid #06F; color:#06F;}
fieldset{border:1px solid #000;}
.noborder{border:#FFF;}
.blueunder{ color:#000000; text-decoration:none;}

.fl{float:left}
.fr{float:right}
.w50{width:50px;}
.w100{width:100px;}
.w160{width:160px;}
.w200{width:200px;}
.w300{width:300px;}
.w400{width:400px;}
.w500{width:500px;}

.h80{height:80px;}
.h100{height:100px;}

.nm{margin:0;}
.mtb2{margin:2px 0;}
.mt{margin-top:5px;}
.mb{margin-bottom:5px;}

input, textarea, select{
	border: 1px solid #000000;
	color: #000000;	
}
</style>
<!--[if lte IE 7]>
<link type="text/css" href="/Public/jcms/css/ie6.css" rel="stylesheet" />
<![endif]-->
</head>    
<body style="background:none;">
<script type="text/javascript" src="<?php echo (TP_CKFINDER); ?>/ckfinder.js"></script>
<script type="text/javascript"> 
var divId=10;
var maxPic='<?php echo ($maxPic); ?>';
function BrowseServer(obj){
	var finder = new CKFinder(); 
	finder.basePath = '<?php echo (TP_CKFINDER); ?>/'; 
	finder.startupPath = 'Images:/News/';
	finder.selectActionFunction = SetFileField;
	finder.selectThumbnailActionFunction = ShowThumbnails;
	finder.popup();
}
function SetFileField(fileUrl,data){
	var sFileName = this.getSelectedFile().name;	
	setView(fileUrl,data,sFileName);
}
function ShowThumbnails(fileUrl,data)
{
	var sFileName = this.getSelectedFile().name;
	setView(fileUrl,data,sFileName);
	return false;
}
function setView(fileUrl,data,sFileName){
	var arr = new Array();
	var val = $("#pic").val();
	if(val!=""){
		var tmp = val.split(",");
		if(tmp.length>=maxPic){
			alert("最多上传图片" + maxPic + "张图片!");
			return false;
		}
		for(var i=0,j=0;i<tmp.length;i++){
			if(tmp[i]==fileUrl){
				alert("您选择的图片已存在!");
				return false;
			}
			if(tmp[i]!=""){
			    arr[j]=tmp[i];
				j++;
			}
		}	
		arr.push(fileUrl);
		var arr = arr.join(",");
		$("#pic").val(arr);
	}else{
		$("#pic").val(fileUrl);
	}
	var thumbid = "thumb"+divId;
	var inputid = "input"+divId;
	var tpl='<div class="thumb" id="'+thumbid+'">' +
				'<img class="thumbimg" src="' + fileUrl + '" height="150"/>' +
				'<div class="caption">' +
					'<input type="hidden" id="' + inputid + '" value="'+ fileUrl +'">' + 
					'<a href="' + data["fileUrl"] + '" target="_blank" class="fl">' + sFileName + '</a> ' +
					'<div onclick="delPic(\'' + thumbid + '\', \'' + inputid + '\')" class="ui-state-default ui-corner-all fl noboder" style="border:none;"><span class="ui-icon ui-icon-circle-minus fl"></span><font class="fl">删除<font></div>' +
				'</div>' +
			'</div>';			
	$("#thumbnails").append(tpl);
	$('#preview').css("display","");
	$("#prompt").css("display","none");
	divId++;
}
function delPic(divid,inputid){
	var val = $("#pic").val();
	var arr = val.split(",");
	var input = $("#"+inputid).val();
	arr.splice($.inArray(input,arr),1);
	var arr = arr.join(",");
	$("#pic").val(arr);
	$("#"+divid).remove();
	if(arr=="")$("#prompt").css("display",""); 
}
$(function(){
    $('#addPart').validate({
        errorPlacement: function(error, element){
            $(element).next('.field_notice').hide();
            $(element).after(error);
        },
        success:function(label){
            label.addClass('right').text('OK!');
        },
        rules : {
            title : {
                required : true
            },
            desc : {
                required : true
            },		
            cid : {
                required : true
            },										
        },
        messages : {
            title : {
                required : '不能为空'
            },
			desc : {
                required : '不能为空'
            },
			cid : {
                required : '请选择'
            },			
        }	
    });
});
</script>
<style>
body{font-size:12px;}
.sminput{width:30px; text-align:center;}
td a{ margin:0 5px;}
tr{ height:40px;}
.red{ color:#F00}
.fl{float:left;}
</style>
<div id="content">
	<div id="main">
    	<div class="pad20">
        	<?php if($myself != 1): ?><ul>
        	<li style="float:left; margin:10px; width:100%">
            	<b style="color:#F00; margin-right:3px;">当前位置:</b><?php echo ($navig); ?>
            </li> 
        </ul>
                <div>
                    <p style="text-align:right;"><input onclick="selflo('<?php echo ($lasturl); ?>')" class="button" type="submit" value="返回上一级" /></p>
                </div><?php endif; ?>
			<div id="tabs">            
                <ul>
               		 <li><a href="#tabs-1"><?php echo ($tabs); ?></a></li>
                </ul>               
                
                <div id="tabs-1">
                <form id="addPart" method="post" action="/index.php?s=/Do/<?php echo ($act); ?>/">
                <input type="hidden" name="model" value="<?php echo ($model); ?>" />
                <input type="hidden" name="act" value="<?php echo ($act); ?>" />
                <input type="hidden" name="callback" value="<?php echo ($callback); ?>" />       
                <input type="hidden" name="id" value="<?php echo ($res['id']); ?>" />                
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr>   
                    	<td>标题：</td>
                    	<td style="padding:8px 0;">
                    <textarea name="title" class="fl" style="height:50px;"><?php echo ($res['title']); ?></textarea><span class="red fl">*</span>必填</label>
                    </td>
                    <tr>   
                    	<td>描述：</td>
                    	<td style="padding:8px 0;">
                    <textarea name="desc" class="fl" style="height:50px;"><?php echo ($res['desc']); ?></textarea><span class="red fl">*</span>必填</label>
                    </td>
                    <tr>   
                        <td>所属分类：</td>
                        <td style="padding:8px 0;">
                            <select id="cid" name="cid" class="input">
                                <option value="">请选择...</option>
                                <?php echo ($cate); ?>
                            </select>
                        </td>
                    </tr>
                    <tr>   
                        <td>封面图片：</td>
                        <td>
                        <input type="hidden" id="pic" name="pic" value="<?php echo ($res['ppic']); ?>"/>
                        <input class="button" type="button" name="upimgBtn" id="upimgBtn" onclick="BrowseServer(this);" value="上传图片" />
                        </td>
                    </tr>
                    <tr>
                 		<td>&nbsp;</td>
                    	<td style="padding:10px 0;">
                    	<?php if(empty($res['pic'])): ?><div id="preview" style="display:none;">
                                <div id="thumbnails"></div>
                            </div>
                            <div id="prompt" style="display:;">
                                <div class="ui-state-default ui-corner-all fl noboder" style="border:none;"><span class="ui-icon ui-icon-alert fl"></span></div>
                                <div class="fl">
                                    请选择封面图片!
                                </div>    
                            </div>  
                         <?php else: ?>   
							<div id="preview">
                                <div id="thumbnails">
                                <?php if(is_array($res['pic'])): $k = 0; $__LIST__ = $res['pic'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($k % 2 );++$k; $e = explode("/",$vo); $e = end($e); ?> 	
                                	<div class="thumb" id="thumb<?php echo ($k); ?>">
                                    	<img class="thumbimg" src="<?php echo ($vo); ?>" height="150">
                                        <div class="caption">
                                        	<input type="hidden" id="input<?php echo ($k); ?>" value="{vo.pic}">
                                            	<a href="<?php echo ($vo); ?>" target="_blank" class="fl"><?php echo ($e); ?></a> 
                                                <div onclick="delPic('thumb<?php echo ($k); ?>', 'input<?php echo ($k); ?>')" class="ui-state-default ui-corner-all fl noboder" style="border:none;"><span class="ui-icon ui-icon-circle-minus fl"></span><font class="fl">删除<font></font></font></div></div></div><?php endforeach; endif; else: echo "" ;endif; ?>    
                                </div>
                            </div>
                            <div id="prompt" style="display:none;">
                                <div class="ui-state-default ui-corner-all fl noboder" style="border:none;"><span class="ui-icon ui-icon-alert fl"></span></div>
                                <div class="fl">
                                    请选择封面图片!
                                </div>    
                            </div><?php endif; ?>       
                    </td>
                 	</tr>
                    <tr>
                    	<td>内容：</td>
                    	<td><?php echo ($html); ?></td>
                    </tr>
                    <tr>
                    	<td colspan="2"><input class="button" type="submit" value="保存" /></td>
                    </tr>
                 </table>
                 </form>
                </div>                                 
			</div>  
        </div>
	</div>
</div>            
                
<div id="SysDel" title="提示!" style="display:none;">
    <p>确定要删除?</p>
</div> 
<div id="SysMove" title="提示!" style="display:none;">
    <p>确定要转移?</p>
</div>
<div id="SysDone" title="提示!" style="display:none;">
    <p>确定要操作?</p>
</div>
<script type="text/javascript" src="/Public/jcms/js/confirm.js"></script>
</body>
</html>